<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.14/vue.js"></script>
</head>
<body>
    <div id="app">
        <grand-father></grand-father>
    </div>
</body>
<script>
Vue.component('grand-father',{
    template: `<div>爷爷组件
        <father></father>    
    </div>`,
    data() {
        return {
            money: 1000
        }
    },
    methods: {
        onPay(num){
            if(this.money-num>=0){
                this.money -= num
            }
        }
    },
})  
Vue.component('father',{
    template: `<div>爸爸组件
        <son></son>
    </div>`
})  
Vue.component('son',{
    mounted() {
        console.log(this.$parent)
    },
    template: `<div>孙子-{{$parent.$parent.money}}--
       <!-- <button @click="$parent.$parent.money -= 100">pay</button> -->
       <button @click="$parent.$parent.onPay(100)">pay</button>
    </div>`
})  

let vm = new Vue({
    el: '#app',
    data(){
        return {
        }
    }
})
</script>
</html>